package com.tcm.kafka;

import kafka.admin.TopicCommand;

public class CreateTopicDemo {

    public static void createTopic(){
        String[] options = new String[]{
          "--zookeeper", "localhost:2181/kafka",
                "--create", "--replication-factor", "1",
                "--partitions", "1",
                "--topic", "topic-connect"
        };
        TopicCommand.main(options);
    }

    public static void describeTopic(){
        String[] options = new String[]{
                "--zookeeper", "localhost:2181/kafka",
                "--describe",
                "--topic", "topic-demo,topic-connect"
        };
        TopicCommand.main(options);
    }

    public static void updatePartition(){
        String[] options = new String[]{
                "--zookeeper", "localhost:2181/kafka",
                "--alter",
                "--topic", "topic-create-api",
                "--partitions", "3"
        };
        TopicCommand.main(options);
    }

    public static void updateTopic(){
        String[] options = new String[]{
                "--zookeeper", "localhost:2181/kafka",
                "--alter",
                "--topic", "topic-create-api",
                "--config", "max.message.bytes=20000"
        };
        TopicCommand.main(options);
    }

    public static void updateTopic2(){
        String[] options = new String[]{
                "--zookeeper", "localhost:2181/kafka",
                "--alter",
                "--entity-type", "topics",
                "--entity-name", "topic-create-api",
                "--add-config",
                "cleanup.policy=compact,max.message.bytes=10000"
        };
        TopicCommand.main(options);
    }

    public static void delTopic(){
        String[] options = new String[]{
                "--zookeeper", "localhost:2181/kafka",
                "--delete",
                "--topic", "topic-connect"
        };
        TopicCommand.main(options);
    }

    public static void main(String[] args) {
//        describeTopic();
        delTopic();
//        createTopic();
    }

}
